<template>
  <div>
    <el-form ref="pram" :model="pram" :rules="rules" label-width="100px" @submit.native.prevent>
      <el-form-item label="年度" prop="year" class="dislabel">
        <el-input v-model.number="pram.year" :maxlength="4" placeholder="年度" />
      </el-form-item>
      <el-form-item label="考评等次" prop="checkResult" class="dislabel">
        <el-select v-model="pram.checkResult" placeholder="考评等次" clearable style="width: 100%">
          <el-option
            v-for="(item,index) in checkData"
            :key="index"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handlerSubmit('pram')" v-hasPermi="['admin:person:update','admin:person:save']">确定</el-button>
        <el-button @click="close">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {Debounce} from '@/utils/validate'
import * as selfUtil from "@/utils/ZBKJIutil";
export default {
  // name: "edit"
  components: { },
  props: {
    isCreate: {
      type: Number,
      required: true
    },
    editData: {
      type: Object,
      default: () => {
        return { rules: [] }
      }
    },
    editKey: {
      type: Number,
      required: true,
      default: -1,
    },
    allCheckData: {
      type: Array
    }
  },
  data() {
    const validateYear = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('请填写年度'));
      } else if (!/^\d{4}$/.test(value)) {
        callback(new Error('年度格式不正确!'));
      } else {
        callback();
      }
    };
    return {
      constants:this.$constants,
      pram: {
        year: null,
        checkResult: null,

        checkResultText:''
      },
      rules: {
        year: [{ required: true, message: '请填正确的年度', validator : validateYear, trigger: ['blur', 'change'] }],
        checkResult: [{ required: true, message: '请选择考评等次', trigger: ['blur', 'change'] }],
      },

      checkData:[]
    }
  },
  mounted() {
    this.initEditData()
  },
  methods: {
    close() {
      this.$emit('hideInfoDialog')
    },

    initEditData() {
      this.checkData = this.allCheckData
    },

    handlerSubmit:Debounce(function(form) {
      this.$refs[form].validate(valid => {
        if (!valid) return
        this.handlerSave()
      })
    }),
    handlerSave() {
      const checkData = this.checkData
      checkData.forEach((item)=>{
        if(item.id === this.pram.checkResult) this.pram.checkResultText = item.name
      })

      this.$emit('assignInfoSaveAndHideInfoDialog',this.pram)
    },
  }
}
</script>

<style scoped lang="scss">
  .dislabel{
    ::v-deep.el-input--small .el-input__inner,
    ::v-deep.el-input--medium .el-input__inner{
      height:36px;
      line-height:36px;
      font-size:12px;
    }
    ::v-deep.el-textarea__inner{
      font-size:12px;
    }

  }
</style>
